package com.fanghaoran.view.user.viewFrame;

import com.fanghaoran.entity.InfoToDisplay;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

/**
 * @Author: win11
 * @Date: 2023/03/27/22:26
 * @Description: 用户间可互相查看的数据表格
 */
public class WordRankTableModel extends AbstractTableModel {
    private final String[] columnNames = {"排名", "用户名","单词数" };
    private final ArrayList<InfoToDisplay> userList;
    private int sequence=0;

    public WordRankTableModel(ArrayList<InfoToDisplay> userList) {
        this.userList = userList;
    }

    @Override
    public int getRowCount() {
        //排名榜最多展示3行
        return Math.min(userList.size(),3);
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        InfoToDisplay user = userList.get(rowIndex);
        switch (columnIndex) {
            case 0:
                if (rowIndex < 3) {
                    // 前三行使用1,2,3作为初始值
                    sequence = rowIndex + 1;
                }
                return sequence;
            case 1:
                return user.getUsername();
            case 2:
                return user.getWordAccount();
            default:
                return null;
        }
    }
    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }


}
